<?php

class Lw_assets
{

    protected $CI;
    protected $assets;
    protected $default;

    public function __construct()
    {
        $this->CI =& get_instance();
        $this->assets = array('cssList' => array(), 'jsList' => array(), 'pageJs' => array(), 'pageCss' => array());
        $this->default = array('sweetalert', 'searchCss');
    }

    // 并将默认样式加入系统当中
    public function getAssets($dataList = array())
    {
        foreach ($this->default as $default) {
            if (!in_array($default, $dataList)) {
                array_push($dataList, $default);
            }
        }
        return $this->getAssetsFromBase($dataList);
    }


    private function getAssetsFromBase($dataList)
    {
        foreach ($dataList as $data) {
            $base = $this->assetsBase();
            if (!isset($base[$data])) {
                continue;
            }
            if (isset($base[$data]['css'])) {
                foreach ($base[$data]['css'] as $css) {
                    array_push($this->assets['cssList'], $css);
                }
            }
            if (isset($base[$data]['js'])) {
                foreach ($base[$data]['js'] as $js) {
                    array_push($this->assets['jsList'], $js);
                }
            }
        }
        return $this->assets;
    }

    private function assetsBase()
    {
        $base = array();
        // backstretch:动态切换图片
        $base['revolution_slider'] = array(
            'css' => array(
                base_url('assets/plugins/revolution_slider/css/rs-style.css'),
                base_url('assets/plugins/revolution_slider/rs-plugin/css/settings.css'),
            ),
            'js' => array(
                base_url('assets/plugins/revolution_slider/rs-plugin/js/jquery.themepunch.plugins.min.js'),
                base_url('assets/plugins/revolution_slider/rs-plugin/js/jquery.themepunch.revolution.min.js'),
            )
        );
        // sweetalert 提示框
        $base['sweetalert'] = array(
            'css' => array(
                base_url('assets/plugins/sweetalert/sweetalert.css'),
            ),
            'js' => array(
                base_url('assets/plugins/sweetalert/sweetalert.min.js'),
            )
        );
        // cubeportfolio 图片管理
        $base['cubeportfolio'] = array(
            'css' => array(
                base_url('assets/plugins/cubeportfolio/css/cubeportfolio.css'),
            ),
            'js' => array(
                base_url('assets/plugins/cubeportfolio/js/jquery.cubeportfolio.min.js'),
            )
        );

        $base['clipboard'] = array(
            'js' => array(
                base_url('assets/plugins/clipboard/clipboard.min.js'),
            )
        );

        // search 页面 CSS
        $base['searchCss'] = array(
            'css' => array(
                base_url('assets/css/search.min.css'),
            ),
        );


        return $base;
    }
}